//用于硬件操作设备 

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include "device.h"
#include "main.h"

extern int g_buttonfd;
extern int g_ledfd;
extern int g_mixerfd;

// open driver file
int InitDriver(void)
{
    // 打开按键设备文件
    g_buttonfd = open("/dev/buttons", O_RDONLY);
    if(-1 == g_buttonfd)
    {
        return FAILURE;
    }

    //打开led设备文件
    g_ledfd = open("/dev/leds", O_WRONLY);
    if(-1 == g_ledfd)
    {
        return FAILURE;
    }
    
    CLOSE_ALL_LED;

    //打开mixer设备文件
    g_mixerfd = open("/dev/mixer", O_WRONLY);
    if(-1 == g_mixerfd)
    {   
        return FAILURE;
    }

    return SUCCESS;
}

int led_on(int which)
{
    ioctl(g_ledfd,1,which);
}

int led_off(int which)
{
    ioctl(g_ledfd,0,which);
}